package storeService

import "time"

type StoreType int

const (
	_ StoreType = iota
	StoreMysql
	StoreMongodb
	storeRedis
)

type Option func(*Options)
type Options struct {
	Type            StoreType //存储类型
	Host            string    //地址
	Port            int       //端口
	User            string    //用户
	Passwd          string    //密码
	Db              string    //db
	Charset         string    //编码
	ConnMaxIdleTime time.Duration
	ConnMaxLifetime time.Duration
	MaxIdleConns    int
	MaxOpenConns    int
}

func newOptions(opts ...Option) *Options {
	opt := &Options{}

	for _, o := range opts {
		o(opt)
	}
	return opt
}

func StoreTyped(t StoreType) Option {
	return func(o *Options) {
		o.Type = t
	}
}

func StoreHost(h string) Option {
	return func(o *Options) {
		o.Host = h
	}
}

func StorePort(p int) Option {
	return func(o *Options) {
		o.Port = p
	}
}

func StoreUser(u string) Option {
	return func(o *Options) {
		o.User = u
	}
}

func StorePasswd(p string) Option {
	return func(o *Options) {
		o.Passwd = p
	}
}

func StoreDb(d string) Option {
	return func(o *Options) {
		o.Db = d
	}
}

func StoreCharset(c string) Option {
	return func(o *Options) {
		o.Charset = c
	}
}

//Mysql
func StoreConnMaxIdleTime(d time.Duration) Option {
	return func(o *Options) {
		o.ConnMaxIdleTime = d
	}
}

func StoreConnMaxLifetime(d time.Duration) Option {
	return func(o *Options) {
		o.ConnMaxLifetime = d
	}
}
func StoreMaxIdleConns(n int) Option {
	return func(o *Options) {
		o.MaxIdleConns = n
	}
}

func StoreMaxOpenConns(n int) Option {
	return func(o *Options) {
		o.MaxOpenConns = n
	}
}
